<?php
header('content-type: application/xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; 

if (!isset($_GET['format'])){ // Initial format discovery query
	echo '<formats><format name="rdf_bibliontology" type="application/xml" docs="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/></formats>';
};

if (isset($_GET['format'])){
	$db_hostname = '127.0.0.1';
	$db_database = 'localpg';
	$db_username = 'root';
	$db_password = '';
	$db_server = mysql_connect($db_hostname, $db_username, $db_password);
	$thispic = $_GET['id'];
	if(!$db_server) die("Unable to connect to MySQL: " .mysql_error());
	
	mysql_select_db($db_database) or die('Unable to connect to MySQL: ' . mysql_error());
	    $query = "SELECT * FROM photo2 JOIN photo ON photo.controlNum=photo2.cnumber WHERE cnumber='". $thispic . "'";
	    $result = mysql_query($query);
	    $ptitle = mysql_result($result, 0,'title');
	    $pshorttitle = preg_replace('/\s+?(\S+)?$/', '', substr($ptitle, 0, 41)) . "...";
	    $pnom = mysql_result($result, 0, 'pname');
	    if ($pnom == "") { $pnom = "Unknown";};
	    $pmon =  intval(mysql_result($result, 0, 'month'));
	    $pdate = $mons[$pmon] . mysql_result($result, 0, 'year');
	    if ($pdate == "0") { $pdate = "Unknown";};
	    $ploc = mysql_result($result, 0, 'state');
	    $pvannum0 = mysql_result($result, 0, 'van0');
	    $pvannum1 = mysql_result($result, 0, 'van1');
	    $pvannum2 = mysql_result($result, 0, 'van2');
	    $medium = mysql_result($result, 0, 'medium');

	    $mediumandsize = mysql_result($result, 0, 'medium');
	    $mediumandsizeexploded = explode(" ; ", $mediumandsize);
	    $medium = $mediumandsizeexploded[0];
	    $size = $mediumandsizeexploded[1];

	    
	
	echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:res="http://purl.org/vocab/resourcelist/schema#" xmlns:z="http://www.zotero.org/namespaces/export#" xmlns:ctag="http://commontag.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:bilbio="http://purl.org/net/biblio#" xmlns:bibo="http://purl.org/ontology/bibo/" xmlns:foaf="http://xmlns.com/foaf/0.1/">
	<bibo:Image rdf:about="http://localhost/photogrammar/records/index.php?record=fsa2000000992/PP">
	<dcterms:title>' . $pshorttitle . '</dcterms:title>
	<dcterms:date>' . $pdate . '</dcterms:date>
	<dcterms:rights>http://www.loc.gov/rr/print/res/071_fsab.html</dcterms:rights>
	<dcterms:subject>' . $pvannum0 . '</dcterms:subject>
	<dcterms:subject>' . $pvannum1 . '</dcterms:subject>
	<dcterms:subject>' . $pvannum2 . '</dcterms:subject>
	<dcterms:abstract>' . $ptitle . '</dcterms:abstract>
	<dcterms:medium>' . $medium . '</dcterms:medium>
	<dcterms:extent>' . $size . '</dcterms:extent>
	<bibo:uri>http://localhost/photogrammar/records/index.php?record=fsa2000000992/PP</bibo:uri>
	<dcterms:creator rdf:nodeID="n7"/>
	<bibo:authorList>
	<foaf:Person rdf:nodeID="n7">
	<foaf:name>' . $pnom .'</foaf:name>
	</foaf:Person>
	</bibo:authorList>
	</bibo:Image>
	</rdf:RDF>';};
?>